package com.jian.java;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author Jiange
 * @create 2021-05-27-21:27
 */
public class JsmTransaction {
    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("");
        Connection connection = factory.createConnection();
        //关闭事务 第二个的签收参数需要有效 设置了事务执行了send 需要执行了commit才会被提交到队列
        Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

        Topic topic = session.createTopic("");
        MessageProducer producer = session.createProducer(topic);
        producer.send(session.createTextMessage(""));

        session.rollback();
        session.commit();
        /**
         * 对于消费者的session的事务也需要commit
         */
        /**
         * 签收有自动签收和手动签收
         */
        /**
         * 在事务会话中、当一个事务被成功提交则消息被自动签收 事务回滚消息会再次被传送
         * 非事务的 消息何时被签收取决于设置
         */
    }
}
